package com.school.zhaoban.pojo;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;


/**
 * <p>
 * 
 * </p>
 *
 * @author 又菜又爱玩
 * @since 2022-02-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="User对象", description="")
@NoArgsConstructor
public class User implements Serializable {

    @TableId(value = "Id", type = IdType.AUTO)
    private Integer Id;

    @NotBlank(message = "用户名不能为空")
    @TableField("userName")
    private String username;

    @TableField("Age")
    private Integer age;

    @NotNull(message = "地址不能为空")
    @TableField("Address")
    private String address;

    @NotNull(message = "手机号不能为空")
    @TableField("Phone")
    private String phone;

    @TableField("Photo")
    private String photo;

    @NotNull(message = "密码不能为空")
    @TableField("password")
    private String password;

    @ApiModelProperty(value = "乐观锁")
    @Version
    private Integer version;

    @ApiModelProperty(value = "逻辑删除")
    @TableLogic
    private Integer deleted;

    @TableField(value = "createTime", fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    private String createtime;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE, value = "updateTime")
    private String updatetime;

    public String getToken(User user) {
        String token="";
        token= JWT.create().withAudience(user.getId() + "")
                .sign(Algorithm.HMAC256(user.getPassword()));
        return token;
    }


}
